package algotithm.weekendrace.biweeklycontest45.test3;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/6-22:20
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
//        String s = "aabccabba";
//        String s = "cabaabac";
        String s = "bbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbccbcbcbccbbabbb";
        int length = solution.minimumLength(s);
        System.out.println(length);
    }


    public int minimumLength(String s) {
        int i=0,j=s.length()-1;
        char[] str = s.toCharArray();
        while (i < j) {
            if (str[i] != str[j]) {
                break;
            }
            char c = str[i];
            while (i <= j && str[i] == c) {
                i++;
            }
            while (i <= j && str[j] == c) {
                j--;
            }
        }
        return j-i+1;
    }

}
